package com.example.templateapp.util

import android.content.Context
import android.text.TextUtils
import android.util.Log
import com.example.templateapp.BuildConfig
import com.tencent.bugly.crashreport.CrashReport
import java.io.BufferedReader
import java.io.FileReader

object BuglyManager {

    fun init(context:Context, key:String = "") {
        if (key.isBlank()) {
            Log.e("BuglyManager", "bugly is not initial")
            return
        }
        CrashReport.initCrashReport(context, key, BuildConfig.DEBUG)
    }

    private fun getProcessName(myPid: Int, context: Context): String? {
        var reader: BufferedReader? = null
        try {
            reader = BufferedReader(FileReader("/proc/$myPid/cmdline"))
            var processName = reader.readLine()
            if (TextUtils.isEmpty(processName).not()) {
                processName = processName.trim()
            }
            return processName
        } catch (throwable: Throwable) {
            throwable.printStackTrace()
        } finally {
            try {
                reader?.close()
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
        return null
    }
}